package com.example.api.service.impl;

import com.example.api.mapper.InventoryMapper;
import com.example.api.model.entity.Inventory;
import com.example.api.service.InventoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class InventoryServiceImpl implements InventoryService {

    @Resource
    private InventoryMapper inventoryMapper;

    @Override
    public Inventory save(Inventory inventory) {
        // 如果是新记录，设置ID
        if (inventory.getId() == null || inventory.getId().isEmpty()) {
            inventory.setId(UUID.randomUUID().toString());
        }
        inventoryMapper.insert(inventory);
        return inventory;
    }

    @Override
    public List<Inventory> findAll() {
        return inventoryMapper.findAll();
    }

    @Override
    public List<Inventory> findByCommodityId(String cid) {
        return inventoryMapper.findAllByCid(cid);
    }

    @Override
    public List<Inventory> findByWarehouseId(String wid) {
        return inventoryMapper.findAllByWid(wid);
    }
}
